package com.HomeWorkhsp.Chapter08.homework.homework12;

public class Test {
    public static void main(String[] args) {
        Teacher teacher = new Teacher("张飞", '男', 30, 5);
        teacher.printInfo();

        System.out.println("--------------------------");

        Student student = new Student("小明", '男', 15, "00023102");
        student.printInfo();

        Person[] person = new Person[4];
        person[0] = new Student("jack", '男', 10, "0001");
        person[1] = new Student("mary", '女', 20, "0002");
        person[2] = new Teacher("smith", '男', 36, 5);
        person[3] = new Teacher("scott", '男', 26, 1);

        Test test = new Test();
        test.bubbleSort(person);

        System.out.println("---排序后的数组---");
        for (int i = 0; i < person.length; i++) {
            System.out.println(person[i]);
        }
        System.out.println("=================");
        for (int i = 0; i < person.length; i++) {
            test.test(person[i]);
        }
    }

    public void test(Person p) {
        if (p instanceof Teacher) {
            ((Teacher) p).teach();
        } else if (p instanceof Student) {
            ((Student) p).study();
        } else {
            System.out.println("do nothing...");
        }
    }

    public void bubbleSort(Person[] person) {
        Person temp = null;
        for (int i = 0; i < person.length - 1; i++) {
            for (int j = 0; j < person.length - i - 1; j++) {
                if (person[j].getAge() < person[j + 1].getAge()) {
                    temp = person[j];
                    person[j] = person[j + 1];
                    person[j + 1] = temp;
                }
            }
        }
    }
}
